package aiku.numericalcontroloa.Base.Configuration;

import cn.dev33.satoken.interceptor.SaInterceptor;
import cn.dev33.satoken.stp.StpUtil;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.ArrayList;
import java.util.List;

@Configuration
public class SaTokenConfigure implements WebMvcConfigurer {
    @Override
    public void addInterceptors(InterceptorRegistry registry) {

        List<String> filtrationList = new ArrayList<>();

        // swagger文档
        filtrationList.add("/swagger-ui.html/*");
        filtrationList.add("/*");

        // 登录 注册
        filtrationList.add("/user/login");
        filtrationList.add("/user/wxLogin");
        filtrationList.add("/user/logout");
        filtrationList.add("/user/register");
        filtrationList.add("/user/sendMail");
        filtrationList.add("/user/verify");
        filtrationList.add("/admin_info");

        filtrationList.add("/employeeProfile/**");
        filtrationList.add("/employeeProfile/updateEmployeeImg");

        filtrationList.add("/static/**");

        // 图片映射
        filtrationList.add("/images/**");

        // 视频映射
        filtrationList.add("/videos/**");

        // 下载Excel
        filtrationList.add("/excel/**");

        filtrationList.add("/word/**");

        // 文件
        // UploadCont.java//177行//162行//update:10-11
        // file后跟对应东西
        filtrationList.add("/files/word/**");
        filtrationList.add("/files/excel/**");
        filtrationList.add("/files/ppt/**");
        filtrationList.add("/files/pdf/**");
        filtrationList.add("/files/weizhi/**");

        registry.addInterceptor(new SaInterceptor(handle -> StpUtil.checkLogin()))
                .addPathPatterns("/**")
                .excludePathPatterns(filtrationList);
    }
}
